package net.htjs.juc.util;

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

@Slf4j
public class ThreadLocalDemo2 {

    public static void main(String[] args) {
        new Thread(() -> {
            Map<String, String> param = new HashMap<>();
            param.put(UserManager.X_USER_ID, "1");
            param.put(UserManager.X_USER_NAME, "张三");
            param.put(UserManager.X_USER_IP, "192.168.0.2");
            UserContextHolder.getInstance().setContext(param);
            log.info("threadName:{}：获取的值{}", Thread.currentThread().getName(), UserContextHolder.getInstance().getContext());
            UserContextHolder.getInstance().remove();
            log.info("threadName:{}：获取的值{}", Thread.currentThread().getName(), UserContextHolder.getInstance().getContext());
        }).start();

        new Thread(() -> {
            Map<String, String> param = new HashMap<>();
            param.put(UserManager.X_USER_ID, "2");
            param.put(UserManager.X_USER_NAME, "李四");
            param.put(UserManager.X_USER_IP, "192.168.0.3");
            UserContextHolder.getInstance().setContext(param);
            log.info("threadName:{}：获取的值{}", Thread.currentThread().getName(), UserContextHolder.getInstance().getContext());
            UserContextHolder.getInstance().remove();
            log.info("threadName:{}：获取的值{}", Thread.currentThread().getName(), UserContextHolder.getInstance().getContext());
        }).start();
    }


}
